/*     */ package com.zimbra.cs.util.tnef.mapi;
/*     */ 
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import java.io.IOException;
/*     */ import java.util.TimeZone;
/*     */ import net.freeutils.tnef.RawInputStream;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TnefTimeZone
/*     */ {
/*     */   public static final String DEFAULT_TNEF_TIMEZONE_ID = "TnefTimeZone";
/*  36 */   static Log sLog = ZimbraLog.tnef;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  43 */   static final int[][] MS_OXOCAL_STANDARD_OFFSET = { { 0, -1 }, { 720, 0 }, { 660, 1 }, { 660, 2 }, { 660, 2 }, { 600, 3 }, { 660, 3 }, { 600, 4 }, { 900, 5 }, { 960, 6 }, { 1020, 6 }, { 1080, 6 }, { 1140, 6 }, { 1200, 6 }, { 1260, 6 }, { 1320, -1 }, { 1380, -1 }, { 0, 7 }, { 120, 8 }, { 150, 8 }, { 180, -1 }, { 240, -1 }, { 300, -1 }, { 390, -1 }, { 480, -1 }, { 510, 9 }, { 540, -1 }, { 600, 10 }, { 930, 11 }, { 780, 12 }, { 840, 12 }, { 720, -1 }, { 900, -1 }, { 960, -1 }, { 1020, -1 }, { 1020, -1 }, { 1080, -1 }, { 1080, 13 }, { 1140, -1 }, { 1440, -1 }, { 0, -1 }, { 60, -1 }, { 120, 14 }, { 120, -1 }, { 150, -1 }, { 240, 15 }, { 360, -1 }, { 420, -1 }, { 450, -1 }, { 600, 16 }, { 600, -1 }, { 540, 12 }, { 120, 17 }, { 120, 18 }, { 150, 18 }, { 120, 19 }, { 960, 20 }, { 240, 8 }, { 1140, 13 }, { 1200, 13 } };
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 109 */   static final int[][][] MS_OXOCAL_STAN_DST_DATES = { { { 10, 0, 5, 2 }, { 3, 0, 5, 1 } }, { { 9, 0, 5, 2 }, { 3, 0, 5, 1 } }, { { 10, 0, 5, 3 }, { 3, 0, 5, 2 } }, { { 9, 0, 5, 1 }, { 3, 0, 5, 0 } }, { { 10, 0, 5, 4 }, { 3, 0, 5, 3 } }, { { 2, 0, 2, 2 }, { 10, 0, 3, 2 } }, { { 11, 0, 1, 2 }, { 3, 0, 2, 2 } }, { { 4, 0, 1, 3 }, { 9, 0, 5, 2 } }, { { 3, 0, 5, 3 }, { 10, 0, 5, 2 } }, { { 9, 2, 4, 2 }, { 3, 0, 1, 2 } }, { { 9, 0, 3, 2 }, { 3, 5, 5, 2 } }, { { 11, 0, 1, 0 }, { 3, 0, 2, 0 } }, { { 10, 0, 5, 1 }, { 3, 0, 5, 0 } }, { { 10, 0, 5, 2 }, { 4, 0, 1, 2 } }, { { 3, 0, 5, 2 }, { 10, 0, 1, 2 } }, { { 9, 0, 2, 2 }, { 4, 0, 2, 2 } }, { { 9, 4, 5, 2 }, { 5, 5, 1, 2 } }, { { 3, 0, 5, 2 }, { 8, 0, 5, 2 } }, { { 4, 0, 1, 3 }, { 10, 0, 5, 2 } }, { { 4, 0, 1, 3 }, { 10, 0, 1, 2 } }, { { 3, 6, 2, 23 }, { 10, 6, 2, 23 } } };
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static TimeZone getTimeZone(int index, boolean observeDaylightSaving, String tzId)
/*     */     throws IOException
/*     */   {
/* 143 */     if ((index < 0) || (index > 59)) {
/* 144 */       return null;
/*     */     }
/* 146 */     int bias = 0;
/* 147 */     int standardBias = 0;
/* 148 */     int daylightBias = 0;
/* 149 */     SYSTEMTIME StandardDate = null;
/* 150 */     SYSTEMTIME DaylightDate = null;
/*     */     
/* 152 */     int startMonth = 0;
/* 153 */     int startDayOfWeek = 0;
/* 154 */     int startDay = 0;
/* 155 */     int startHour = 0;
/*     */     
/* 157 */     int endMonth = 0;
/* 158 */     int endDayOfWeek = 0;
/* 159 */     int endDay = 0;
/* 160 */     int endHour = 0;
/*     */     
/*     */ 
/* 163 */     int utcPlus12offset = MS_OXOCAL_STANDARD_OFFSET[index][0];
/* 164 */     int indexToDaytimeSavingDatesTable = MS_OXOCAL_STANDARD_OFFSET[index][1];
/*     */     
/* 166 */     if (utcPlus12offset > 720) {
/* 167 */       bias = (utcPlus12offset - 720) * -1;
/* 168 */     } else if (utcPlus12offset < 720) {
/* 169 */       bias = 720 - utcPlus12offset;
/*     */     }
/* 171 */     if ((indexToDaytimeSavingDatesTable == -1) || (!observeDaylightSaving)) {
/* 172 */       int utcOffsetInMilliseconds = bias * 60 * 1000;
/* 173 */       return getNoDaylightSavingTimeZoneFromUtcOffset(utcOffsetInMilliseconds);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 181 */     bias *= -1;
/*     */     
/*     */ 
/*     */ 
/* 185 */     daylightBias = -60;
/*     */     
/* 187 */     startMonth = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][1][0];
/* 188 */     startDayOfWeek = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][1][1];
/* 189 */     startDay = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][1][2];
/* 190 */     startHour = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][1][3];
/*     */     
/* 192 */     endMonth = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][0][0];
/* 193 */     endDayOfWeek = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][0][1];
/* 194 */     endDay = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][0][2];
/* 195 */     endHour = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][0][3];
/*     */     
/* 197 */     StandardDate = new SYSTEMTIME(endMonth, endDayOfWeek, endDay, endHour);
/* 198 */     DaylightDate = new SYSTEMTIME(startMonth, startDayOfWeek, startDay, startHour);
/*     */     
/* 200 */     if (sLog.isDebugEnabled()) {
/* 201 */       StringBuilder debugInfo = new StringBuilder();
/* 202 */       debugInfo.append(bias * -1 + " " + "{" + endMonth + "," + endDayOfWeek + "," + endDay + "," + endHour + "} " + "{" + startMonth + "," + startDayOfWeek + "," + startDay + "," + startHour + "}");
/*     */       
/*     */ 
/* 205 */       sLog.debug(debugInfo);
/*     */     }
/*     */     String timeZoneId;
/*     */     String timeZoneId;
/* 209 */     if ((tzId == null) || (tzId.length() == 0)) {
/* 210 */       timeZoneId = "TnefTimeZone";
/*     */     } else {
/* 212 */       timeZoneId = tzId;
/*     */     }
/* 214 */     TimeZoneDefinition timeZoneDefinition = new TimeZoneDefinition(timeZoneId, bias, standardBias, daylightBias, StandardDate, DaylightDate);
/* 215 */     return timeZoneDefinition.getTimeZone();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private static TimeZone getNoDaylightSavingTimeZoneFromUtcOffset(int utcOffsetInMilliseconds)
/*     */   {
/* 224 */     String[] ids = TimeZone.getAvailableIDs(utcOffsetInMilliseconds);
/* 225 */     for (int i = 0; i < ids.length; i++) {
/* 226 */       if (TimeZone.getTimeZone(ids[i]).getDSTSavings() == 0) {
/* 227 */         return TimeZone.getTimeZone(ids[i]);
/*     */       }
/*     */     }
/* 230 */     return null;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static TimeZone getTimeZone(RawInputStream ris)
/*     */     throws IOException
/*     */   {
/* 246 */     return getTimeZone(ris, null);
/*     */   }
/*     */   
/*     */   public static TimeZone getTimeZone(RawInputStream ris, String tzId) throws IOException {
/* 250 */     int index = ris.readU16();
/* 251 */     boolean observeDaylightSaving = (ris.readU16() & 0x8000) != 32768;
/* 252 */     return getTimeZone(index, observeDaylightSaving, tzId);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/util/tnef/mapi/TnefTimeZone.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */